package com.ocom.srvpaccess.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ocom.common.entity.master.EntityMjDeviceList;
import com.ocom.common.enums.DataSourceEnum;
import com.ocom.common.enums.MasterSlaveEnum;
import com.ocom.mysql.aspect.DataSourceAspect;
import com.ocom.srvpaccess.dao.IDaoDeviceList;
import com.ocom.srvpaccess.service.DeviceListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.Date;


@Service
public class DeviceListServiceImpl extends ServiceImpl<IDaoDeviceList, EntityMjDeviceList> implements DeviceListService {


    @Autowired
    private IDaoDeviceList daoDeviceList;

    //修改总库mj_device_list表：
    //update mj_device_list
    //set status=0, end_time = EndDate
    //				where com_id= companyId and device_no=machNo
    @DataSourceAspect(type= DataSourceEnum.MAIN_DB,isMaster = MasterSlaveEnum.MASTER)
    @Override
    public void updateEndTime(Long companyId, String machNo) {
        QueryWrapper<EntityMjDeviceList> query = Wrappers.query();
        query.eq("com_id",companyId);
        query.eq("device_no",machNo);
        EntityMjDeviceList entityMjDeviceList = new EntityMjDeviceList();
        entityMjDeviceList.setStatus(0);
        Date date = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.YEAR, 3);
        entityMjDeviceList.setEndTime(calendar.getTime());
        daoDeviceList.update(entityMjDeviceList,query);
    }

}
